package message

import (
	"api/common"
	"api/pb/message"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateMessageStatusLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateMessageStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateMessageStatusLogic {
	return &UpdateMessageStatusLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// UpdateMessageStatus 更新消息状态(撤回/删除)
func (l *UpdateMessageStatusLogic) UpdateMessageStatus(req *types.UpdateStatusRequest) (resp *types.Empty, err error) {
	// 1. 获取用户标识
	userID, err := common.GetUserIDFromCtx(l.ctx)
	if err != nil {
		return nil, err
	}
	// 2. 更新消息状态
	_, err = l.svcCtx.MessageRPC.UpdateStatus(l.ctx,
		&message.UpdateStatusRequest{Id: req.ID, UserId: userID, Status: req.Status})
	if err != nil {
		return nil, err
	}
	return &types.Empty{}, nil
}
